package com.liang.maogouyuyin.utils

import android.net.Uri
import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.ExoPlayer
import com.liang.maogouyuyin.TheBaseApplication

object PlayerUtil {
    private val exoPlayer = ExoPlayer.Builder(TheBaseApplication.context).build()

    fun playAudio(path: String) {
        stopAudio()
        val mediaItem = MediaItem.fromUri(Uri.parse(path))
        exoPlayer.setMediaItem(mediaItem)
        exoPlayer.prepare()
        exoPlayer.play()
    }

    fun stopAudio() {
        if (exoPlayer.isPlaying)
            exoPlayer.stop()
    }
}